package com.ate.myview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.viewpager.widget.ViewPager;

/**
 * @author Ate
 * @description:
 * @date :2020/12/18 10:34
 */
public class MyViewPager extends ViewPager {
    private boolean isScroll = true;//true可滑动 false不可滑动

    public MyViewPager(Context context) {
        super(context);
    }

    public MyViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (isScroll) {
            return super.onTouchEvent(ev);//消费
        } else {
            return false; //不消费所以不可滑动
        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (isScroll) {
            return super.onInterceptTouchEvent(ev);
        } else {
            return false;//不拦截，可以达到子控件
        }
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        return super.dispatchTouchEvent(ev);
    }

    public void setIsScroll(boolean isScroll) {   //实例设置是否禁用滑动方法
        this.isScroll = isScroll;
    }
}